package com.ruoyi.tester.executor.expression;

import com.ruoyi.tester.executor.ExpressionContext;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * @author SongJun
 * @description TODO:
 * @date 2021/6/10 16:38
 */
@Component
public class ExpDayOFWeek extends AbstractExpTime {
    private String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};


    @Override
    public String getExpressionName() {
        return "dayOfWeek";
    }

    @Override
    public String getDescription() {
        return "dayOfWeek() 返回中文格式的当前星期几, 如: 星期二;"+super.getDescription();
    }

    @Override
    public Object analysis(ExpressionContext context, String... param) {
        Calendar calendar = (Calendar)super.analysis(context, param);

        int i = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (i < 0){
            i = 0;
        }
        return weekDays[i];
    }

}
